package main

import (
	"fmt"
	"sync"
	"sync/atomic"
)

var count int

func main() {
	var count int64
	var wg sync.WaitGroup

	for i := 0; i < 10000; i++ {
		wg.Add(1)
		go func(wg *sync.WaitGroup) {
			defer wg.Done()
			for {
				old := atomic.LoadInt64(&count)
				if atomic.CompareAndSwapInt64(&count, old, old+1) {
					break
				}

			}
		}(&wg)
		wg.Wait()
		fmt.Println("count = ", count)
	}
}
